package com.devbobcorn.misaka.blocks;

import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.HorizontalFaceBlock;
import net.minecraft.item.BlockItemUseContext;
import net.minecraft.state.StateContainer;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.util.math.shapes.VoxelShapes;
import net.minecraft.world.IBlockReader;

public class GekotaBlock extends HorizontalFaceBlock {
    protected static final VoxelShape X_BODY_SHAPE = Block.box(6.0D, 0.0D, 5.0D, 10.0D, 6.0D, 11.0D);
    protected static final VoxelShape Z_BODY_SHAPE = Block.box(5.0D, 0.0D, 6.0D, 11.0D, 6.0D, 10.0D);
    
    protected static final VoxelShape X_HEAD_SHAPE = Block.box(5.0D, 6.0D, 4.0D, 11.0D, 13.0D, 12.0D);
    protected static final VoxelShape Z_HEAD_SHAPE = Block.box(4.0D, 6.0D, 5.0D, 12.0D, 13.0D, 11.0D);

    protected static final VoxelShape X_SHAPE = VoxelShapes.or(X_BODY_SHAPE, X_HEAD_SHAPE);
    protected static final VoxelShape Z_SHAPE = VoxelShapes.or(Z_BODY_SHAPE, Z_HEAD_SHAPE);

    protected GekotaBlock(Properties settings) {
        super(settings);
        this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH));
    }

    protected void createBlockStateDefinition(StateContainer.Builder<Block, BlockState> builder) {
        builder.add(FACING);
    }

    public BlockState getStateForPlacement(BlockItemUseContext ctx) {
        return this.defaultBlockState().setValue(FACING, ctx.getHorizontalDirection().getOpposite());
    }

    public VoxelShape getShape(BlockState state, IBlockReader world, BlockPos pos, ISelectionContext ctx) {
        return state.getValue(FACING).getAxis() == Direction.Axis.X ? X_SHAPE : Z_SHAPE;
    }
    
}
